const Koa = require('koa')
const getIpv4 = require('./utils/index')
// 引入axios
const axios = require('axios')

const app = new Koa()

// 所有的请求都会进入到这个函数中处理

app.use(async (ctx, next) => {
    const start = +new Date()
    console.log(start)
    await next()
    const delta = +new Date() - start
    console.log(delta)
    // console.log(ctx.state.baiduHTML)

})
// 第二个中间件
app.use(async (ctx, next) => {
    const url = 'http://www.baidu.com'
    // const res = await axios.get(url)
    // console.log(res)
    ctx.state.baiduHTML = await axios.get(url)
})


app.listen(3000, () => {
    console.log(`my server is running at http://${getIpv4()}:3000`)
})